package com.gsn.chooseChannel;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.GsnImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.gsn.chooseRoom.ChooseRoomScreen;
import com.gsn.common.ShopGold;
import com.gsn.dataCommon.ConfigModel;
import com.gsn.dataCommon.UserData;
import com.gsn.desktop.engine.ActorUtility;
import com.gsn.poker.asset.FontTexture;
import com.gsn.poker.asset.PokerSound;
import com.gsn.poker.asset.PortalTexture;
import com.gsn.poker.game.MyPoker;

public class ButtonShop extends Group {
	GsnImageButton shopButton;
	Group parent;
	long gold;
	long xu;
	int id;

	public ButtonShop(int id, Group parent) {
		this.id = id;
		this.parent = parent;
		PortalTexture portalTexture = PortalTexture.inst();
		// TODO Auto-generated constructor stub
		shopButton = new GsnImageButton(portalTexture.changeGoldButton, portalTexture.changeGoldPress);
		portalTexture.scaleActor(shopButton);
		addActor(shopButton);

		Label labelGold = new Label(ActorUtility.formatNumber(ConfigModel.shopModelList[id].bean) + " =", new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(1, 1, 0.3f, 1)));
		gold = ConfigModel.shopModelList[id].bean;
		addActor(labelGold);
		labelGold.x = shopButton.getRealWidth() * 0.2f;
		labelGold.y = shopButton.getRealHeight() * 0.1f;

		Label labelXu = new Label(ActorUtility.formatNumber(ConfigModel.shopModelList[id].coin), new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(0, 1, 0, 1)));
		addActor(labelXu);
		xu = ConfigModel.shopModelList[id].coin;
		labelXu.x = shopButton.getRealWidth() * 0.2f;
		labelXu.y = shopButton.getRealHeight() * 0.6f;
		width = shopButton.getRealWidth();
		height = shopButton.getRealHeight();

		shopButton.setClickListener(new ClickListener() {

			@Override
			public void click(Actor actor, float x, float y) {
				// TODO Auto-generated method stub

				PokerSound.playClick();
				if (ButtonShop.this.parent instanceof ListShopGold)
					((ListShopGold) ButtonShop.this.parent).showParticle(ButtonShop.this, x, y);
				else if (ButtonShop.this.parent instanceof ShopGold)
					((ShopGold) ButtonShop.this.parent).showParticle(ButtonShop.this, x, y);
				if (UserData.xu < ConfigModel.shopModelList[ButtonShop.this.id].coin) {
					if (MyPoker.game.currentScreen instanceof ChooseRoomScreen) {
						MyPoker.game.chooseRoomScreen.showNotEnoughMoney();
					} else {
						MyPoker.game.chooseChannelScreen.showNotEnoughMoney();
					}

				} else {
					// shopGold(ConfigModel.shopModelList[_position].coin,
					// ConfigModel.shopModelList[_position].bean, _position);
					if (MyPoker.game.currentScreen instanceof ChooseChannelScreen)
						MyPoker.game.chooseChannelScreen.showChangeGold(xu, gold, ButtonShop.this.id);
					else
						MyPoker.game.chooseRoomScreen.showChangeGold(xu, gold, ButtonShop.this.id);

				}

			}
		});

	}

}
